package com.ruoyi.web.controller.djb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.djb.domain.DjbAdmin;
import com.ruoyi.djb.service.IDjbAdminService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * APP用户管理Controller
 * 
 * @author xxd
 * @date 2023-12-08
 */
@Controller
@RequestMapping("/djb/adminUser")
public class DjbAdminController extends BaseController
{
    private String prefix = "djb/adminUser";

    @Autowired
    private IDjbAdminService djbAdminService;

    @RequiresPermissions("djb:adminUser:view")
    @GetMapping()
    public String adminUser()
    {
        return prefix + "/adminUser";
    }

    /**
     * 查询APP用户管理列表
     */
    @RequiresPermissions("djb:adminUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbAdmin djbAdmin)
    {
        startPage();
        List<DjbAdmin> list = djbAdminService.selectDjbAdminList(djbAdmin);
        return getDataTable(list);
    }

    /**
     * 导出APP用户管理列表
     */
    @RequiresPermissions("djb:adminUser:export")
    @Log(title = "APP用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbAdmin djbAdmin)
    {
        List<DjbAdmin> list = djbAdminService.selectDjbAdminList(djbAdmin);
        ExcelUtil<DjbAdmin> util = new ExcelUtil<DjbAdmin>(DjbAdmin.class);
        return util.exportExcel(list, "APP用户管理数据");
    }

    /**
     * 新增APP用户管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存APP用户管理
     */
    @RequiresPermissions("djb:adminUser:add")
    @Log(title = "APP用户管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbAdmin djbAdmin)
    {
        return toAjax(djbAdminService.insertDjbAdmin(djbAdmin));
    }

    /**
     * 修改APP用户管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbAdmin djbAdmin = djbAdminService.selectDjbAdminById(id);
        mmap.put("djbAdmin", djbAdmin);
        return prefix + "/edit";
    }

    /**
     * 修改保存APP用户管理
     */
    @RequiresPermissions("djb:adminUser:edit")
    @Log(title = "APP用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbAdmin djbAdmin)
    {
        return toAjax(djbAdminService.updateDjbAdmin(djbAdmin));
    }

    /**
     * 删除APP用户管理
     */
    @RequiresPermissions("djb:adminUser:remove")
    @Log(title = "APP用户管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbAdminService.deleteDjbAdminByIds(ids));
    }
}
